package com.wzbc.video.controller;

import com.wzbc.video.api.CommonResult;
import com.wzbc.video.entity.Chapter;
import com.wzbc.video.req.*;
import com.wzbc.video.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/chapter")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    @PostMapping("/getChapter")
    public CommonResult getChapter(@RequestBody ChapterReq req){
        if(req.getLessonId()==0L){
            return CommonResult.failed("请不要跨过课程直接进来");
        }
        return CommonResult.success(chapterService.getChapter(req));
    }

    @PostMapping("/getChapterDown")
    public CommonResult getChapterDown(@RequestBody ChapterDownReq req){
        if(req.getLessonId()==0L){
            return CommonResult.failed("请不要跨过课程直接进来");
        }
        return CommonResult.success(chapterService.getChapterDown(req));
    }

    @PostMapping("/getOne")
    public CommonResult getOne(@RequestBody IdReq req){
        if(req.getId()==null || req.getId()==0L){
            return CommonResult.failed("没有id为0的章节");
        }
        return CommonResult.success(chapterService.getChapterOne(req.getId()));
    }
    @PostMapping("/insert")
    public CommonResult insertChapter(@RequestBody Chapter chapter) {
        return CommonResult.success(chapterService.insert(chapter));
    }

    @PostMapping("/delete")
    public CommonResult deleteChapter(@RequestBody ChapterIdReq req){
        return CommonResult.success(chapterService.deleteById(req.getChapterId()));
    }

    @PostMapping("/change")
    public CommonResult changeChapter(@RequestBody Chapter chapter){
        return CommonResult.success(chapterService.updateById(chapter));
    }
}
